package cn.dckeji.dcssm.common.aspect;

import cn.dckeji.dcssm.common.utils.LogUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import java.text.SimpleDateFormat;
import java.util.Arrays;

/**
 * @author kenny
 * @Title: ApiAspect
 * @ProjectName dcssm
 * @Description: 请求接口详情aop
 * @date 2019/3/4 15:34
 */
@Aspect
public class ApiAspect {
    private long start = 0;
    //controller包的子包里面任何方法
    @Pointcut("execution(* cn.dckeji.dcssm.controller..*.*(..))")
    public void checkToken() {
    }

    @Before("checkToken()")
    public void beforeCheckToken() {
        start = System.currentTimeMillis();
    }

    @AfterReturning("checkToken()")
    public void afterCheckToken(JoinPoint point) {
        long end = System.currentTimeMillis();
        LogUtil.logDebug(
                "\n====================================================================" +
                        "\n|请求时间："+new SimpleDateFormat("hh:mm:ss").format(start)+
                        "\n|耗时："+(end-start)+ "毫秒" +
                        "\n|URI: "+point.getSignature().toString()+
                        "\n|参数为:"+ Arrays.toString(point.getArgs())+
                        "\n====================================================================");
    }
}
